//
//  HHBaseLoadToken.m
//  caishuitong
//
//  Created by qiysoft on 2017/4/28.
//  Copyright © 2017年 zhangxy. All rights reserved.
//

#import "HHBaseLoadToken.h"
#import "CommonFunc.h"
#import "WShareUtil.h"

@implementation HHBaseLoadToken

- (void)loadToken {

    NSString *uuurl = @"http://mobile.csfw360.com:18082/csfw_jiekou/common/queryToken";
    NSString *uuid= @"e1e1e1";

    NSDictionary *parametersDict = @{@"jqbh":uuid,@"uid":@"141978",@"password":@"1"};
    //    NSDictionary *parametersDict = @{@"jqbh":uuid};

    // 字典转成JSon字符串
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];

    [WHttpTool POST:uuurl parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        NSString *createTime = [returnDic objectForKey:@"createTime"];
        NSString *endTime = [returnDic objectForKey:@"endTime"];
        NSString *jqbh = [returnDic objectForKey:@"jqbh"];
        NSString *token = [returnDic objectForKey:@"token"];
        WLog(@"创建时间-> %@",createTime);
        WLog(@"结束时间-> %@",endTime);
        WLog(@"机器编号-> %@",jqbh);
        WLog(@"token令牌-> %@",token);
        [WShareUtil sharedData].strToken = token;

        if ([self tokenBlock]) {
            [self tokenBlock](token);
        }

    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];
}

@end
